<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script src="crypto-js-4.1.1.min.js"></script>
<script>
    // AES ECB模式加密
    function aes_ecb_encrypt(text, keyStr) {
        var key = CryptoJS.enc.Utf8.parse(keyStr);
        // 加密
        var encryptedData = CryptoJS.AES.encrypt("左传魁", key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return encryptedData.ciphertext.toString();
    }

    // AES ECB模式解密
    function aes_ecb_decrypt(ciphertext, keyStr) {
        var key = CryptoJS.enc.Utf8.parse(keyStr);
        // 拿到字符串类型的密文需要先将其用Hex方法parse一下
        var encryptedHexStr = CryptoJS.enc.Hex.parse(ciphertext);
        // 将密文转为Base64的字符串 只有Base64类型的字符串密文才能对其进行解密
        var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);
        //使用转为Base64编码后的字符串即可传入CryptoJS.AES.decrypt方法中进行解密操作。
        var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return decryptedData.toString(CryptoJS.enc.Utf8);
    }

    const key = 'Pi_jC7#zK8JmLZO2';
    console.log(aes_ecb_decrypt("9b9874307ca887e56d700b7d702a5295", key));
    console.log(aes_ecb_encrypt("admin", key));

    getKey();

    function getKey() {
        var str = "Pi_jC7#zK8JmLZO2";
        var ss = '';
        for (const strElement of str) {
            console.log(strElement.charCodeAt());
            ss += strElement.charCodeAt() + ",";
        }
        console.log(ss);

    }

    console.log(getYear());

    function getYear() {
        var now = new Date();
        var year = now.getFullYear();
        return '' + year;
    }


    function yyyymm() {
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var clock = year + "-";
        if (month < 10)
            clock += "0";
        clock += month;
        return clock;
    }

    function today() {
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var day = now.getDate();
        var hh = now.getHours();
        var mm = now.getMinutes();
        var ss = now.getSeconds();
        var clock = year + "-";
        if (month < 10)
            clock += "0";
        clock += month + "-";
        if (day < 10)
            clock += "0";
        clock += day;
        return clock;
    }

    function getDatetime() {
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var day = now.getDate();
        var hh = now.getHours();
        var mm = now.getMinutes();
        var ss = now.getSeconds();
        var clock = year + "-";
        if (month < 10)
            clock += "0";
        clock += month + "-";
        if (day < 10)
            clock += "0";
        clock += day + " ";
        if (hh < 10)
            clock += "0";
        clock += hh + ":";
        if (mm < 10) clock += '0';
        clock += mm + ":";
        if (ss < 10) clock += '0';
        clock += ss;
        return clock;
    }

    //获取当年第一天
    function getFirstDayOfYear() {
        var date = new Date();
        date.setDate(1);
        date.setMonth(0);
        return timeFormat(date);
    }

    //获取当月第一天
    function getFirstDayOfMonth() {
        var date = new Date();
        date.setDate(1);
        return timeFormat(date);
    }

    //获取这周的周一
    function getFirstDayOfWeek() {
        var date = new Date();
        //获取星期几,getDay()返回值是 0（周日） 到 6（周六） 之间的一个整数。0||7为7，即weekday的值为1-7
        var weekday = date.getDay() || 7;
        //往前算（weekday-1）天，年份、月份会自动变化
        date.setDate(date.getDate() - weekday + 1);
        return timeFormat(date);
    }

    //获取当季第一天
    function getFirstDayOfSeason () {
        var date = new Date();
        var month = date.getMonth();
        if(month <3 ){
            date.setMonth(0);
        }else if(2 < month && month < 6){
            date.setMonth(3);
        }else if(5 < month && month < 9){
            date.setMonth(6);
        }else if(8 < month && month < 11){
            date.setMonth(9);
        }
        date.setDate(1);
        return timeFormat(date);
    }

    //获取这周的周一
    function getFirstDayOfWeek () {
        var date = new Date();
        var weekday = date.getDay()||7;
        date.setDate(date.getDate()-weekday+1);
        return timeFormat(date);
    }
    function timeFormat(date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        if (m < 10) {
            m = '0' + m;
        }
        var d = date.getDate();
        if (d < 10) {
            d = '0' + d;
        }
        return y + "-" + m + "-" + d;
    }
</script>
</html>
